﻿@using System.Data;
@{
    ViewBag.Title = "UserManage";
}
<script src="@Url.Content("~/Scripts/userdelitem.js")" type="text/javascript"></script>
<script type="text/javascript">
    var usermanageurl = '@Url.Action("UserManage")';
    var sortorder = '@ViewBag.sortorder';
    var sortparam = 'sortorder=' + sortorder;
    $('#itemname_search').val('@ViewBag.itemname_search');
    $('#itemSN_search').val('@ViewBag.itemSN_search');
    $('#addtime_search').val('@ViewBag.addtime_search');
    $('#linkaddr_search').val('@ViewBag.linkaddr_search');
    var searchparam = 'itemname=' + '@ViewBag.itemname_search' + '&itemSN=' + '@ViewBag.itemSN_search' + '&addtime=' + '@ViewBag.addtime_search' + '&linkaddr=' + '@ViewBag.linkaddr_search';
    var pageparam = 'page=' + '@ViewBag.pagenumber';
    function generateUrl() {
        return usermanageurl + '?' + searchparam + '&' + sortparam + '&' + pageparam;
    }
    function firstpage() {
        pageparam = 'page=1';
        window.location = generateUrl();
    }
    function lastpage(pagecount) {
        pageparam = 'page=' + pagecount;
        window.location = generateUrl();
    }
    function prevpage(pagenumber) {
        pageparam = 'page=' + (pagenumber - 1);
        window.location = generateUrl();
    }
    function nextpage(pagenumber) {
        pageparam = 'page=' + (pagenumber + 1);
        window.location = generateUrl();
    }
</script>
<h2>
    商品管理</h2>
<div>
    <ul>
        <li>@Html.ActionLink("品牌资料", "UserBrand")</li><li>@Html.ActionLink("商品管理", "UserManage")</li>
    </ul>
</div>@*这两项要添加到左栏*@
@{
    
    int i;
    DataView items = ViewBag.itemlist;
    int pagenumber = ViewBag.pagenumber;
    int pagecount = ViewBag.pagecount;
    <table border="1" style="table-layout:fixed;word-break:break-all; word-wrap:break-all; text-align:center;margin:auto;">
        
            <tr>
                <th style="width:25px;">
                    
                </th>
                <th style="width:100px;">
                    预览
                </th>
                <th style="width:250px;">
                    名称
                </th>
                <th style="width:100px;"> 
                    <div id="grid_itemSN" value="">
                        价格</div>
                </th>
                <th style="width:250px;">
                    <div id="grid_addtime" value="">
                        添加时间</div>
                </th>
                <th style="width:200px;">
                    链接地址
                </th>
                <th style="width:25px;">
                    
                </th>
            </tr>
        
        @*<tr>
            <td>
                <button id="clear_search">
                    清空搜索</button>
            </td>
            <td>@Html.TextBox("itemname_search")
            </td>
            <td>@Html.TextBox("itemSN_search")
            </td>
            <td>
            </td>
            <td>@Html.TextBox("addtime_search")
            </td>
            <td>@Html.TextBox("linkaddr_search")
            </td>
            <td>
                <button id="grid_search">
                    搜索</button>
            </td>
        </tr>*@
        @for (i = 0; i < items.Count; i++)
        {
            <tr>
                <td>@Html.CheckBox(items[i][0].ToString(), false)
                </td>
                <td>@*@items[i][3].ToString()*@
                <span>
                <img width="50px" src="@Href("~/uploads/" + items[i][3].ToString())" alt="image" />
                </span>
                </td>
                <td>@items[i][1].ToString()
                </td>
                <td>@items[i][6].ToString()
                </td>
                
                <td>@items[i][4].ToString()
                </td>
                <td>@items[i][5].ToString()
                </td>
                <td>@Html.ActionLink("编辑", "UserEditItem", "Manage", new { itemid = items[i][0].ToString(),orginpagenumber=pagenumber,orginsortorder=ViewBag.sortorder,itemname_search=ViewBag.itemname_search,
                                                                             itemSN_search=ViewBag.itemSN_search,addtime_search=ViewBag.addtime_search,linkaddr_search=ViewBag.linkaddr_search}, null)
                </td>
            </tr>
        
        }
    </table>
}
@helper PageLink(int pagenumber, int pagecount)
    {
    <div id="pager">
        @if (pagenumber == 1)
        {
            <text>第一页 前一页 </text>
        }
        else
        {
            <a onclick="firstpage()">第一页</a>
            <a onclick="prevpage(@pagenumber)">前一页</a>
        }
        <span>当前第 @pagenumber 页 共 @pagecount 页</span>
        @if (pagenumber == pagecount)
        {
            <text>后一页 最后一页</text>
        }
        else
        {
            <a onclick="nextpage(@pagenumber)">后一页</a>
            <a onclick="lastpage(@pagecount)">最后一页</a>
        }
    </div>
}
<div style="text-align:center;" id="gridbar">
    
    @PageLink(pagenumber, pagecount)
</div>
<div style="text-align:center;">
    <button onclick="window.location='@Url.Action("UserAddItem", new
                                 {
                                     orginpagenumber = pagenumber,
                                     orginsortorder = ViewBag.sortorder,
                                     itemname_search = ViewBag.itemname_search,
                                     itemSN_search = ViewBag.itemSN_search,
                                     addtime_search = ViewBag.addtime_search,
                                     linkaddr_search = ViewBag.linkaddr_search
                                 })'">
        添加商品</button><button onclick="getdelitemid('@Url.Action("UserDelItem")')">
            删除商品</button></div>
<script src="@Url.Content("~/Scripts/showgrid.js")" type="text/javascript"></script>
